package com.wangyk.thymeleafproject.controller;

import com.wangyk.rabbitmqcommon.model.console.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * 测试Ribbon的负载均衡
 */
@Controller
@RequestMapping("/ribbon")
public class RibbonController
{
    //3.第三种方式，使用注解
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/test_ribbon.do")
    @ResponseBody
    public User testRibbon()
    {
        //3.第三种方式，使用LoadBalance注解，使用服务名即可
        User user = restTemplate.getForObject(
            "http://" + "SPIRNG-BOOT-RABBITMQ" + "/rabbitmq/userpro/test_ribbon.do", User.class);
        return user;
    }
}
